﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SDF.Web.Models;
using PetaPoco;

namespace SDF.Web
{
    public partial class exam_search : SDF.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //所有
                gv.DataSource = db.Fetch<AuthRule>("select  Title from AuthRule where id>0");
                gv.DataBind();
            }
        }

        //模糊查询
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string key = string.Format("%{0}%", txtKey.Text);
            gv.DataSource = db.Fetch<AuthRule>("where title like @0", key);
            gv.DataBind();
        }


        //多条件查询
        protected void btnSearchMul_Click(object sender, EventArgs e)
        {
            string title = txtTitle.Text;
            string status = txtStatus.Text;

            //非参数式，注意过滤
            //string sql = string.Format("where title like '%{0}%' and Status={1}", title, status);

            //参数化
            var sql = Sql.Builder.Append("select * from AuthRule")
                  .Append("where title like @0", string.Format("%{0}%", title))
                  .Append("where status=@0", status);

            gv.DataSource = db.Fetch<AuthRule>(sql);
            gv.DataBind();
        }
    }
}